﻿using System;
using System.Collections.Generic;
using System.Net.Sockets;
using ApplLogic.ApplClasses;
using ConnectionObjects;

namespace TCPClient.RequestsToServerHandlers
{
    public class RequestsToServerHandlerForManager : RequestsToServerHandler
    {
        private ApplManager m_LoggedInManager;

        public RequestsToServerHandlerForManager(NetworkStream streamRef, ApplManager loggedinManager)
            :base(streamRef)
        {
            m_LoggedInManager = loggedinManager;
        }

        public ApplManager LoggedInManager { get { return m_LoggedInManager; }

        }

 
        #region FirstConfigurationMethods

        public OutConnectionObject ChangeDefaultPeriodBetweenShiftsForRunningAlgo(string newPeriod)
        {
            object[] paramsArr = new object[1];
            paramsArr[0] = newPeriod;
            InConnectionObject con = new InConnectionObject("ChangeDefaultPeriodBetweenShiftsForRunningAlgo", paramsArr, !k_HasReturnValue);
            sendMessage(con);
            return getMessage(); 
        }

        public OutConnectionObject ChangeNumberOfShiftsPerDay(string numberOfShiftsPerDay)
        {
            object[] paramsArr = new object[1];
            paramsArr[0] = numberOfShiftsPerDay;
            InConnectionObject con = new InConnectionObject("ChangeNumberOfShiftsPerDay", paramsArr, !k_HasReturnValue);
            sendMessage(con);
            return getMessage(); 
        }

        public OutConnectionObject ChangeLenghtOfShift(string lenghtOfShift)
        {
            object[] paramsArr = new object[1];
            paramsArr[0] = lenghtOfShift;
            InConnectionObject con = new InConnectionObject("ChangeLenghtOfShift", paramsArr, !k_HasReturnValue);
            sendMessage(con);
            return getMessage();  
        }


        public OutConnectionObject ChangeStartTimeOfWork(string startOfWork)
        {
            object[] paramsArr = new object[1];
            paramsArr[0] = startOfWork;
            InConnectionObject con = new InConnectionObject("ChangeStartTimeOfWork", paramsArr, !k_HasReturnValue);
            sendMessage(con);
            return getMessage();
        }

        public OutConnectionObject ChangeNumberOfWorkersPerShift(string numberOfWorkersPerShift)
        {
            object[] paramsArr = new object[1];
            paramsArr[0] = numberOfWorkersPerShift;
            InConnectionObject con = new InConnectionObject("ChangeNumberOfWorkersPerShift", paramsArr, !k_HasReturnValue);
            sendMessage(con);
            return getMessage();
        }

        #endregion


        #region Requests from Server 

        public OutConnectionObject ShowShiftDetails(DateTime startTime, DateTime endTime)
        {
            object[] paramsArr = new object[2];
            paramsArr[0] = startTime;
            paramsArr[1] = endTime;
            InConnectionObject con = new InConnectionObject("ShowShiftDetails", paramsArr, k_HasReturnValue);
            sendMessage(con);
            return getMessage();
        }

        public OutConnectionObject RunAlgo(DateTime startTime, DateTime endTime)
        {
            object[] paramsArr = new object[2];
            paramsArr[0] = startTime;
            paramsArr[1] = endTime;
            InConnectionObject con = new InConnectionObject("RunAlgo", paramsArr, !k_HasReturnValue);
            sendMessage(con);
            return getMessage();
        }

        public OutConnectionObject GetAllWorkersThatGotShiftInStep(string shiftId, eResult result, DateTime startTime, DateTime endTime)
        {
            object[] paramsArr = new object[4];
            paramsArr[0] = shiftId;
            paramsArr[1] = result;
            paramsArr[2] = startTime;
            paramsArr[3] = endTime;
            InConnectionObject con = new InConnectionObject("GetAllWorkersThatGotShiftInStep", paramsArr, k_HasReturnValue);
            sendMessage(con);
            return getMessage();
        }

        public OutConnectionObject GetAllResultsOfAllShiftsOfWorker(DateTime startTime, DateTime endTime, string workerId)
        {
            object[] paramsArr = new object[3];
            paramsArr[0] = startTime;
            paramsArr[1] = endTime;
            paramsArr[2] = workerId;
            InConnectionObject con = new InConnectionObject("GetAllResultsOfAllShiftsOfWorker", paramsArr, k_HasReturnValue);
            sendMessage(con);
            return getMessage();
        }

        public OutConnectionObject GetAllWorkersThatAskedForAShiftWithType(string shiftId, eType type, DateTime startTime, DateTime endTime)
        {
            object[] paramsArr = new object[4];
            paramsArr[0] = shiftId;
            paramsArr[1] = type;
            paramsArr[2] = startTime;
            paramsArr[3] = endTime;
            InConnectionObject con = new InConnectionObject("GetAllWorkersThatAskedForAShiftWithType", paramsArr, k_HasReturnValue);
            sendMessage(con);
            return getMessage();
        }

        public OutConnectionObject UpdateShift(ApplShift updatedShift)
        {
            object[] paramsArr = new object[1];
            paramsArr[0] = updatedShift;
            InConnectionObject con = new InConnectionObject("UpdateShift", paramsArr, !k_HasReturnValue);
            sendMessage(con);
            return getMessage();
        }

        public OutConnectionObject AddResultShiftToWorker(string workerId, DateTime startTime, DateTime endTime)
        {
            object[] paramsArr = new object[3];
            paramsArr[0] = workerId;
            paramsArr[1] = startTime;
            paramsArr[2] = endTime;
            InConnectionObject con = new InConnectionObject("AddResultShiftToWorker", paramsArr, !k_HasReturnValue);
            sendMessage(con);
            return getMessage();
        }

        public OutConnectionObject DeleteResult(string workerId, DateTime startTime, DateTime endTime)
        {
            object[] paramsArr = new object[3];
            paramsArr[0] = workerId;
            paramsArr[1] = startTime;
            paramsArr[2] = endTime;
            InConnectionObject con = new InConnectionObject("DeleteResult", paramsArr, !k_HasReturnValue);
            sendMessage(con);
            return getMessage();
        }

        public OutConnectionObject ChangeResultRegistrationOfAworker(string workerId, DateTime startTimeToremove, DateTime endTimeToRemove,
            DateTime startTimeToAdd, DateTime endTimeToAdd)
        {
            object[] paramsArr = new object[5];
            paramsArr[0] = workerId;
            paramsArr[1] = startTimeToremove;
            paramsArr[2] = endTimeToRemove;
            paramsArr[3] = startTimeToAdd;
            paramsArr[4] = endTimeToAdd;
            InConnectionObject con = new InConnectionObject("ChangeResultRegistrationOfAworker", paramsArr, !k_HasReturnValue);
            sendMessage(con);
            return getMessage();
        }

        public OutConnectionObject AddWorker(ApplWorker workerToAdd)
        {
            object[] paramsArr = new object[1];
            paramsArr[0] = workerToAdd;
            InConnectionObject con = new InConnectionObject("AddWorker", paramsArr, !k_HasReturnValue);
            sendMessage(con);
            return getMessage();
        }

        public OutConnectionObject AddShift(ApplShift shiftToAdd)
        {
            object[] paramsArr = new object[1];
            paramsArr[0] = shiftToAdd;
            InConnectionObject con = new InConnectionObject("AddShift", paramsArr, !k_HasReturnValue);
            sendMessage(con);
            return getMessage();
        }

        public OutConnectionObject DeleteWorker(string workerId)
        {
            object[] paramsArr = new object[1];
            paramsArr[0] = workerId;
            InConnectionObject con = new InConnectionObject("DeleteWorker", paramsArr, !k_HasReturnValue);
            sendMessage(con);
            return getMessage();
        }

        public OutConnectionObject DeleteShift(string shiftId)
        {
            object[] paramsArr = new object[1];
            paramsArr[0] = shiftId;
            InConnectionObject con = new InConnectionObject("DeleteShift", paramsArr, !k_HasReturnValue);
            sendMessage(con);
            return getMessage();
        }

        public OutConnectionObject AddSingleShiftResult(ApplSingleResult singleResultToAdd)
        {
            object[] paramsArr = new object[1];
            paramsArr[0] = singleResultToAdd;
            InConnectionObject con = new InConnectionObject("AddSingleShiftResult", paramsArr, !k_HasReturnValue);
            sendMessage(con);
            return getMessage();
        }

        public OutConnectionObject UpdateSingleShiftResult(ApplSingleResult singleResultToUpdate)
        {
            object[] paramsArr = new object[1];
            paramsArr[0] = singleResultToUpdate;
            InConnectionObject con = new InConnectionObject("UpdateSingleShiftResult", paramsArr, !k_HasReturnValue);
            sendMessage(con);
            return getMessage();
        }

        public OutConnectionObject DeleteSingleShiftResult(string workerId, string shiftId)
        {
            object[] paramsArr = new object[2];
            paramsArr[0] = workerId;
            paramsArr[1] = shiftId;
            InConnectionObject con = new InConnectionObject("DeleteSingleShiftResult", paramsArr, !k_HasReturnValue);
            sendMessage(con);
            return getMessage();  
        }

        public OutConnectionObject GetAllRequestsOfAllWorkers(DateTime startTime, DateTime endTime)
        {
            object[] paramsArr = new object[2];
            paramsArr[0] = startTime;
            paramsArr[1] = endTime;
            InConnectionObject con = new InConnectionObject("GetAllRequestsOfAllWorkers", paramsArr, k_HasReturnValue);
            sendMessage(con);
            return getMessage();
        }

        public OutConnectionObject GetAllRequestsOfAllWorkersWithType(eType type, DateTime startTime, DateTime endTime)
        {
            object[] paramsArr = new object[3];
            paramsArr[0] = type;
            paramsArr[1] = startTime;
            paramsArr[2] = endTime;
            InConnectionObject con = new InConnectionObject("GetAllRequestsOfAllWorkersWithType", paramsArr, k_HasReturnValue);
            sendMessage(con);
            return getMessage();
        }

        public OutConnectionObject GetAllRequestsOfAllShifts(DateTime startTime, DateTime endTime)
        {
            object[] paramsArr = new object[2];
            paramsArr[0] = startTime;
            paramsArr[1] = endTime;
            InConnectionObject con = new InConnectionObject("GetAllRequestsOfAllShifts", paramsArr, k_HasReturnValue);
            sendMessage(con);
            return getMessage();
        }

        public OutConnectionObject GetAllRequestsOfAllShiftsWithType(eType type, DateTime startTime, DateTime endTime)
        {
            object[] paramsArr = new object[3];
            paramsArr[0] = type;
            paramsArr[1] = startTime;
            paramsArr[2] = endTime;
            InConnectionObject con = new InConnectionObject("GetAllRequestsOfAllShiftsWithType", paramsArr, k_HasReturnValue);
            sendMessage(con);
            return getMessage();
        }

        public OutConnectionObject GetAllWorkersThatAskedForShiftsInRange(DateTime startTime, DateTime endTime)
        {
            object[] paramsArr = new object[2];
            paramsArr[0] = startTime;
            paramsArr[1] = endTime;
            InConnectionObject con = new InConnectionObject("GetAllWorkersThatAskedForShiftsInRange", paramsArr, k_HasReturnValue);
            sendMessage(con);
            return getMessage();
        }

        public OutConnectionObject GetAllWorkersThatNotAskedForanyShiftInRange(DateTime startTime, DateTime endTime)
        {
            object[] paramsArr = new object[2];
            paramsArr[0] = startTime;
            paramsArr[1] = endTime;
            InConnectionObject con = new InConnectionObject("GetAllWorkersThatNotAskedForanyShiftInRange", paramsArr, k_HasReturnValue);
            sendMessage(con);
            return getMessage();
        }

        public OutConnectionObject GetAllResultsOfAllWorkers(DateTime startTime, DateTime endTime)
        {
            object[] paramsArr = new object[2];
            paramsArr[0] = startTime;
            paramsArr[1] = endTime;
            InConnectionObject con = new InConnectionObject("GetAllResultsOfAllWorkers", paramsArr, k_HasReturnValue);
            sendMessage(con);
            return getMessage();
        }

        public OutConnectionObject GetAllResultsOfAllWorkersWithResult(eResult result, DateTime startTime, DateTime endTime)
        {
            object[] paramsArr = new object[3];
            paramsArr[0] = result;
            paramsArr[1] = startTime;
            paramsArr[2] = endTime;
            InConnectionObject con = new InConnectionObject("GetAllResultsOfAllWorkersWithResult", paramsArr, k_HasReturnValue);
            sendMessage(con);
            return getMessage();
        }

        public OutConnectionObject GetAllResultsOfAllShifts(DateTime startTime, DateTime endTime)
        {
            object[] paramsArr = new object[2];
            paramsArr[0] = startTime;
            paramsArr[1] = endTime;
            InConnectionObject con = new InConnectionObject("GetAllResultsOfAllShifts", paramsArr, k_HasReturnValue);
            sendMessage(con);
            return getMessage();
        }

        public OutConnectionObject GetAllResultsOfAllShiftsWithResult(eResult result, DateTime startTime, DateTime endTime)
        {
            object[] paramsArr = new object[3];
            paramsArr[0] = result;
            paramsArr[1] = startTime;
            paramsArr[2] = endTime;
            InConnectionObject con = new InConnectionObject("GetAllResultsOfAllShiftsWithResult", paramsArr, k_HasReturnValue);
            sendMessage(con);
            return getMessage();
        }

        public OutConnectionObject GetAllWorkers()
        {
            InConnectionObject con = new InConnectionObject("GetAllWorkers", null, k_HasReturnValue);
            sendMessage(con);
            return getMessage();
        }

        public OutConnectionObject NotifyAllWorkersForNewShiftCreation(DateTime startTime, DateTime endTime, string additionalInfo)
        {
            object[] paramsArr = new object[3];
            paramsArr[0] = startTime;
            paramsArr[1] = endTime;
            paramsArr[2] = additionalInfo;
            InConnectionObject con = new InConnectionObject("NotifyAllWorkersForNewShiftCreation", paramsArr, !k_HasReturnValue);
            sendMessage(con);
            return getMessage();
        }

        public OutConnectionObject NotifyWorkersThatnNotSendRequests(DateTime startTime, DateTime endTime, string additionalInfo)
        {
            object[] paramsArr = new object[3];
            paramsArr[0] = startTime;
            paramsArr[1] = endTime;
            paramsArr[2] = additionalInfo;
            InConnectionObject con = new InConnectionObject("NotifyWorkersThatnNotSendRequests", paramsArr, !k_HasReturnValue);
            sendMessage(con);
            return getMessage();
        }

        public OutConnectionObject GetAllRequestsOfAllShiftsOfWorker(DateTime startTime, DateTime endTime, string workerId)
        {
            object[] paramsArr = new object[3];
            paramsArr[0] = startTime;
            paramsArr[1] = endTime;
            paramsArr[2] = workerId;
            InConnectionObject con = new InConnectionObject("GetAllRequestsOfAllShiftsOfWorker", paramsArr, k_HasReturnValue);
            sendMessage(con);
            return getMessage();
        }

        #endregion
    }
}
